home *** CD-ROM | disk | FTP | other *** search
/ Mac Expert 1995 Winter / Mac Expert - Winter 95.iso / Les fichiers / Communications / Divers / DinkClass ƒ / DC Scribble / ScribleMainProgram.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-16  |  3.6 KB  |  179 lines  |  [TEXT/KAHL]

  1. /*
  2.     File:        ScribleMainProgram.c
  3.  
  4.     Written by:    Mark Gross
  5.  
  6.     Copyright:    © 1992 by Applied Technical Software, all rights reserved.
  7.     Use at your own risk.
  8.  
  9. */
  10.  
  11. //
  12. // this is the model main function modual for the typical DinkClass
  13. // application
  14. //
  15.  
  16. #include "DApplication.h"
  17. #include "DScribbleApp.h"
  18. #include "DScribbleDoc.h"
  19. #include "DinkUtils.h"
  20.  
  21. //
  22. //Core apple event prototypes
  23. //
  24. void DoAEInstallation(void);
  25.  
  26. pascal OSErr HandleQUIT( AppleEvent *theAppleEvent, AppleEvent *reply,
  27.                          long myRefCon);
  28. pascal OSErr HandleOAPP( AppleEvent *theAppleEvent, AppleEvent *reply, 
  29.                          long myRefCon);
  30. pascal OSErr HandlePDOC( AppleEvent *theAppleEvent, AppleEvent *reply,
  31.                          long myRefCon);
  32. pascal OSErr HandleODOC( AppleEvent *theAppleEvent, AppleEvent *reply,
  33.                          long myRefCon);
  34.  
  35.  
  36. main()
  37. {
  38.     DApplication    *theApp;
  39.     
  40.     InitToolBox(5);
  41.  
  42.     if(!System7Available() )
  43.         DebugStr( "\p No System 7!!" );
  44.  
  45.     DEventHandler::gApplication = NULL;// to make sure no messages get sent to gApplication 
  46.                                     // before it is instanicated.  otherwise the Application
  47.                                     // object will be sending install handler message to itself
  48.                                     // befor it is fully instaniated.
  49.     
  50.     theApp = new DScribbleApp;
  51.     
  52.     DEventHandler::gApplication = theApp;
  53.     DEventHandler::gPassItOn = TRUE;
  54.  
  55.     theApp->fCreator = 'MkGR';// use your faverate initials
  56.     theApp->fClipType = 'PICT';
  57.     theApp->fMainFileType = 'PICT';
  58.  
  59.     DoAEInstallation();// the AE-handler procs refrence gApplication 
  60.                         // so I'm initializing the AEvents after I have
  61.                         // a valid gApplication
  62.     
  63.     
  64.     if(theApp->InitApp() )
  65.     {            
  66.         theApp->MakeDDoc(FALSE);
  67.         do
  68.         {
  69.             theApp->EventLoop();
  70.         } while(!theApp->CleanUp());
  71.     }
  72.     delete theApp;
  73.     ExitToShell();    //last good bye kiss
  74. }// the end
  75.  
  76.  
  77.  
  78.  
  79.  
  80. void DoAEInstallation(void)
  81. {
  82.  
  83.     AEInstallEventHandler( kCoreEventClass, kAEOpenDocuments,
  84.                             (EventHandlerProcPtr)HandleODOC, 0, false);
  85.  
  86.     AEInstallEventHandler( kCoreEventClass, kAEQuitApplication,
  87.                             (EventHandlerProcPtr)HandleQUIT, 0, false);
  88.  
  89.     AEInstallEventHandler( kCoreEventClass, kAEPrintDocuments,
  90.                             (EventHandlerProcPtr)HandlePDOC, 0, false);
  91.  
  92.     AEInstallEventHandler( kCoreEventClass, kAEOpenApplication,
  93.                             (EventHandlerProcPtr)HandleOAPP, 0, false);
  94.  
  95. }                            
  96.  
  97.  
  98.  
  99. pascal OSErr HandleQUIT( AppleEvent *theAppleEvent, AppleEvent *reply, long myRefCon)
  100. {
  101.     OSErr myErr;
  102.     
  103.     myErr = RequiredCheck( theAppleEvent);
  104.     if (myErr) 
  105.         return myErr;
  106.     
  107.     DEventHandler::gApplication->fDone = true;
  108.     return noErr;
  109. }
  110.  
  111.  
  112.  
  113. pascal OSErr HandleOAPP( AppleEvent *theAppleEvent, AppleEvent *reply, long myRefCon)
  114. {
  115.     OSErr myErr;
  116.  
  117.     myErr = RequiredCheck( theAppleEvent);
  118.     if (myErr) 
  119.         return myErr;
  120.     
  121.     return noErr;
  122. }
  123.  
  124.  
  125.  
  126. pascal OSErr HandlePDOC( AppleEvent *theAppleEvent, AppleEvent *reply, long myRefCon)
  127. {
  128.     OSErr myErr;
  129.  
  130.     myErr = RequiredCheck( theAppleEvent);
  131.     if (myErr) 
  132.         return myErr;
  133.     
  134.     return errAEEventNotHandled;
  135. }
  136.  
  137.  
  138. pascal OSErr HandleODOC( AppleEvent *theAppleEvent, AppleEvent *reply, long myRefCon)
  139. {
  140.     OSErr myErr;
  141.     AEDescList  docList;
  142.     FSSpec        myFSS;
  143.     long        i;
  144.     long        itemsInList;
  145.     AEKeyword    theKeyWord;
  146.     DescType    typeCode;
  147.     Size        actualSize;
  148.     WindowPtr    docWindow;
  149.     DDocument* newDoc;
  150.  
  151.     myErr = AEGetParamDesc(theAppleEvent, keyDirectObject, typeAEList, &docList);
  152.     if ( myErr)
  153.         return(myErr);
  154.  
  155.     myErr = RequiredCheck( theAppleEvent);
  156.     if (myErr) 
  157.         return myErr;
  158.  
  159.  
  160.     myErr = AECountItems(&docList, &itemsInList);
  161.     if (myErr) 
  162.         return myErr;
  163.         
  164.     for (i = 1; ((i <= itemsInList) && (!myErr)); ++i) 
  165.     {
  166.         myErr = AEGetNthPtr( &docList, i, typeFSS, &theKeyWord,    &typeCode, 
  167.             (Ptr)&myFSS, sizeof(FSSpec), &actualSize );
  168.         
  169.         if (myErr) 
  170.             return myErr;
  171.         
  172.         newDoc = new DScribbleDoc;
  173.         if (newDoc)
  174.             newDoc->AEInitDoc(&myFSS); 
  175.     }
  176.     return noErr;
  177. }
  178.  
  179.